package com.binfast.codegen.controller;

import com.binfast.codegen.model.params.generate.GenerateParam;
import com.binfast.codegen.services.GenerateServ;
import com.binfast.codegen.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class GenerateCtrl {

    @Autowired
    GenerateServ generateServ;

    @PostMapping(value = "/all.do")
    @ResponseBody
    public Result genAllCode(String preTableName, String tableName,String tableTitle) {
        GenerateParam param = new GenerateParam(preTableName,tableName,tableTitle);
        return Result.success(generateServ.generateAllCode(param),true);
    }

    @PostMapping(value = "/page.do")
    @ResponseBody
    public Result genPage(String preTableName,String tableName,String tableTitle) {
        GenerateParam param = new GenerateParam(preTableName,tableName,tableTitle);
        return Result.success(generateServ.generatePaegCode(param),true);
    }

    @PostMapping(value = "/java.do")
    @ResponseBody
    public Result genJava(String preTableName,String tableName,String tableTitle) {
        GenerateParam param = new GenerateParam(preTableName,tableName,tableTitle);
        return Result.success(generateServ.generateJavaCode(param));
    }

    @RequestMapping("/layout")
    public ModelAndView login() {
        ModelAndView view = new ModelAndView("/layout.html");
        return view;
    }

    @RequestMapping("/")
    public ModelAndView index() {
        ModelAndView view = new ModelAndView("index.html");
        return view;
    }
}
